package com.wechat.admin.service.impl;

import com.wechat.admin.model.dto.AssignmentDeviceDto;
import com.wechat.admin.model.dto.DockerTokenDto;
import com.wechat.admin.model.dto.UserInfoDto;
import com.wechat.admin.model.dto.WeDeviceDto;
import com.wechat.admin.model.entity.TokenGroupLink;
import com.wechat.admin.model.entity.User;
import com.wechat.admin.model.entity.UserDeviceLink;
import com.wechat.admin.model.vo.AssignmentDeviceVo;
import com.wechat.admin.model.vo.DockerTokenVo;
import com.wechat.admin.model.vo.UsableDeviceVo;
import com.wechat.admin.service.ConverterService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author:sjb
 * @CreateTime:2024-12-19
 * @Description: 实现类
 * @Version：1.0
 */
@Service
public class ConverterServiceImpl implements ConverterService {

    @Override
    public List<DockerTokenVo> dockerTokenDtoToVo(List<DockerTokenDto> dockerTokenDto) {
        return dockerTokenDto.stream().map(dto -> {
            DockerTokenVo dockerTokenVo = new DockerTokenVo();
            dockerTokenVo.setTokenName(dto.getDeviceName());
            dockerTokenVo.setToken(dto.getGeweToken());
            return dockerTokenVo;
        }).collect(Collectors.toList());
    }

    @Override
    public List<UsableDeviceVo> usableDeviceObjToVo(List<WeDeviceDto> weDeviceDtoList) {
        return weDeviceDtoList.stream().map(weDeviceDto -> {
            UsableDeviceVo usableDeviceVo = new UsableDeviceVo();
            usableDeviceVo.setDeviceName(weDeviceDto.getDeviceName());
            usableDeviceVo.setToken(weDeviceDto.getToken());
            usableDeviceVo.setJointTime(weDeviceDto.getAssignedAtTime());
            return usableDeviceVo;
        }).collect(Collectors.toList());
    }

    @Override
    public List<AssignmentDeviceVo.Device> assignmentDeviceDtoToVo(List<AssignmentDeviceDto> assignmentDeviceDtoList) {
        return assignmentDeviceDtoList.stream().map(assignmentDeviceDto -> {
            AssignmentDeviceVo.Device assignmentDeviceVo = new AssignmentDeviceVo.Device();
            assignmentDeviceVo.setDeviceName(assignmentDeviceDto.getDeviceName());
            assignmentDeviceVo.setUserName(assignmentDeviceDto.getUserName());
            assignmentDeviceVo.setGroupName(assignmentDeviceDto.getGroupName());
            assignmentDeviceVo.setAssignTime(assignmentDeviceDto.getJoinedAtTime());
            return assignmentDeviceVo;
        }).collect(Collectors.toList());
    }
}
